# Copyright (c) 2010 The Foundry Visionmongers Ltd.  All Rights Reserved. #

import maya.cmds as cmds
import sys
import os.path
import maya2scenegraphXML

reload(maya2scenegraphXML)


chr_dict = {
    'c003_XTmama_normal_geometry_GRP': {
        'assembly': ['c003_XTmama_normal_head_GRP', 'c003_XTmama_normal_body_GRP'],
        'component': ['c003_XTmama_normal_brow_GRP', 'c003_XTmama_normal_lash_GRP', 'c003_XTmama_normal_eye_GRP',
                      'c003_XTmama_normal_ear_GRP', 'c003_XTmama_normal_mouth_GRP', 'c003_XTmama_normal_tar_GRP',
                      'c003_XTmama_normal_headAss_GRP', 'c003_XTmama_normal_bodyAss_GRP', 'c003_XTmama_normal_R_shoe_GRP',
                      'c003_XTmama_normal_L_shoe_GRP', 'c003_XTmama_normal_L_hand', 'c003_XTmama_normal_R_hand',
                      'c003_XTmama_normal_body']
    },
    'c004_XTbaba_normal_geometry_GRP': {
        'assembly': ['c004_XTbaba_normal_head_GRP'],
        'component': ['c004_XTbaba_normal_brow_GRP', 'c004_XTbaba_normal_lash_GRP', 'c004_XTbaba_normal_eye_GRP',
                      'c004_XTbaba_normal_ear_GRP', 'c004_XTbaba_normal_mouth_GRP', 'c004_XTbaba_normal_headAss_GRP',
                      'c004_XTbaba_normal_tar_GRP', 'c004_XTbaba_normal_bodyAss_GRP', 'c004_XTbaba_normal_R_hand_GRP',
                      'c004_XTbaba_normal_L_hand_GRP', 'c004_XTbaba_normal_R_shoe_GRP', 'c004_XTbaba_normal_L_shoe_GRP',
                      'c004_XTbaba_normal_body_GRP']
    }
}
prop_dict = {
    'p299_erji_normal_geometry_GRP': {
        'assembly': [],
        'component': ['p299_erji_normal_erjiwaike_GRP', 'p299_erji_normal_neierdian_GRP', 'p299_erji_normal_ruandian_GRP',
                      'p299_erji_normal_suliaoyanjin_GRP', 'p299_erji_normal_yanzhuzi_GRP']
    }
}
env_dict = {
    'b019_chengfeiji_normal_geometry_GRP': {
        'assembly': ['b019_chengfeiji_normal_ditan_GRP',],
        'component': ['b019_chengfeiji_normal_jitibufen_GRP', 'b019_chengfeiji_normal_boli_GRP', 'b019_chengfeiji_normal_tanxianwei_GRP',
                      'b019_chengfeiji_normal_zhongkong_GRP', 'b019_chengfeiji_normal_kongjian_GRP',
                      'b019_chengfeiji_normal_jiaoqiandian_GRP', 'b019_chengfeiji_normal_zoulang_GRP', 'b019_chengfeiji_normal_baobian_GRP',
                      'b019_chengfeiji_normal_dengpao_GRP', 'b019_chengfeiji_normal_light_GRP', 'b019_chengfeiji_normal_wifi_GRP',
                      'b019_chengfeiji_normal_yizi_GRP', 'b019_chengfeiji_normal_qiang_GRP', 'b019_chengfeiji_normal_bujianA_GRP',
                      'b019_chengfeiji_normal_gaibanB_GRP', 'b019_chengfeiji_normal_gaibanA_GRP', 'b019_chengfeiji_normal_men_GRP',
                      'b019_chengfeiji_normal_ruandian_GRP', 'p325_jixiehaibao_normal', 'mod_modify', 'light_Mod','light_Mod1']
    }
}


for dic in [chr_dict, prop_dict]:
    for values in dic.values():
        maya2scenegraphXML.setAssembly(values['assembly'])
        maya2scenegraphXML.setComponent(values['component'])
for dic in [env_dict]:
    for values in dic.values():
        maya2scenegraphXML.setAssembly(values['assembly'])
        maya2scenegraphXML.setStaticComponent(values['component'])



fileName = 'sc004_shot0322'
root_path = '/mnt/project/bao/Proj_Maya/new_project/scenes/scenegraphWrite'

roots = chr_dict.keys() + prop_dict.keys() + env_dict.keys()
for k in roots:
    maya2scenegraphXML.setArbAttr([k], 'lookfile', "%s/%s.klf" %(root_path, k[:-13]), 'string')


maya2scenegraphXML.maya2ScenegraphXML(roots, '%s/%s_data_abc/%s.xml' %(root_path, fileName, fileName),
                                      startFrame=1101,
                                      endFrame=1105,
                                      arbAttrs=['lookfile'],
                                      )

# proxyGroups = cmds.ls("*_lod_lo")
# for proxyGroup in proxyGroups:
#     proxyFileName = proxyGroup[:-7] + "_proxy.abc"
#     proxyFilePath = os.path.join(exportDirectory, proxyFileName)
#     print "Exporting Proxy: %s" % proxyFilePath
#     cmds.AbcExport(j="-uv -root %s -file %s" % (proxyGroup, proxyFilePath))

#maya2scenegraphXML.deleteSgxmlAttrs('c003_XTmama_normal_body_GRP')